<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of menu_model
 *
 * @author agasi
 */
class Menu_model extends CI_Model {
    //put your code here
    function __construct() 
    {
        parent::__construct();
    }
    
    function get_menu($groupId = 1) 
    {
        $sql = "SELECT distinct CONCAT(REPEAT('', level - 1), 
               CAST(hi.menu_id AS CHAR)) AS menu_id, 
               parent_menu_id, 
               menu_title,
               mdl_link,
               mdl_id,
               level
            FROM    (
                    SELECT  hierarchy_connect_by_parent_eq_prior_id(menu_id) AS id, @level AS level
                    FROM    (
                            SELECT  
                     @start_with := 0,
                                    @id := @start_with,
                                    @level := 0
                            ) vars, sys_menu
                    WHERE   @id IS NOT NULL
                    ) ho
            JOIN    sys_menu hi ON hi.menu_id = ho.id
            jOIN sys_group_menu ON `menu_id` = grpmenu_menu_id
            JOIN sys_group ON grpmenu_grp_id = grp_id
            JOIN sys_module ON mdl_id = menu_mdl_id
            WHERE grp_id like ?"; 
        
        $query = $this->db->query($sql, array($groupId));       
        return $query->result_array();
    }
}

/* End of file menu_model.php */
/* Location: ./application/model/sistem_menu_model.php */